$(function(){
    layui.use(['layer','form'], function(){
        var form = layui.form;
        var layer = layui.layer;

          //手机号密码验证
          form.verify({
              password: [/(.+){6,12}$/, '密码必须6到12位'],
          });

        $.ajaxSetup({
               headers: {
                  'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
               }
        });

		//修改用户密码
        form.on('submit(pwdbutton)', function(data){
            // alert(JSON.stringify(data.field))
            // return false
			   var action = data.form.action;//表单提交URL地址
            $.post(action, data.field, function(obj){
                //根据返回结果作出相应处理
                // alert(obj);return false;
                    if (obj.code == 200)
                    {
                        layer.msg(obj.status+':'+obj.msg,{time:1000,icon:1}, function(){
                            layer.close('edit');
                            location.href = location.href;
                          })
                    }
                    else if(obj.code == 400 || obj.code == 401)
                    {
                         layer.msg(obj.status+':'+obj.msg)
                    }

            },'json');
            return false;//注释掉这行代码后，表单将会以普通方式提交表单，否则以ajax方式提交表单

        });
	})
})